package com.yuheadline.article.controller;

import com.dust.yuheadline.common.utils.Result;
import com.yuheadline.article.service.ArticleService;
import com.yuheadline.model.article.domain.Article;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 高翔宇
 * @since 2025/4/19 周六 13:48
 */
@Slf4j
@RestController
@RequestMapping("/api/article")
@RequiredArgsConstructor
@Tag(name = "文章管理接口")
public class ArticleController {
    private final ArticleService articleService;

    /**
     * 保存文章
     */
    @PostMapping("/submit")
    @Operation(summary = "保存文章")
    public Result<Long> submitArticle(@RequestBody Article article) {
        log.info("保存文章");
        return articleService.submitArticle(article);
    }


    /**
     * 查询文章列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询文章列表")
    public Result<List<Article>> getArticleList() {
        log.info("查询文章列表");
        return articleService.getArticleList();
    }

    /**
     * 删除文章
     */
    @DeleteMapping("/{id}")
    @Operation(summary = "删除文章")
    public Result<Void> deleteArticle(@PathVariable Long id) {
        log.info("删除文章");
        return articleService.deleteArticle(id);
    }

    /**
     * 根据id获取文章
     */
    @GetMapping("/{id}")
    @Operation(summary = "根据id获取文章")
    public Result<Article> getArticleById(@PathVariable Long id) {
        log.info("根据id获取文章");
        return articleService.getArticleById(id);
    }
}
